package com.example.Windturbine.Controller;

import com.example.Windturbine.DataObject.ProductInfoDO;
import com.example.Windturbine.Error.BusinessException;
import com.example.Windturbine.Response.CommonResult;
import com.example.Windturbine.Service.CacheService;
import com.example.Windturbine.Service.FunctionService;
import com.example.Windturbine.Service.Model.ProductModel;
import com.example.Windturbine.Service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.util.List;

/**
 * @Author 丁永新
 * @Date 2021/12/18
 */
@Slf4j
@Controller("function")
@RequestMapping("/function")
@CrossOrigin(allowCredentials = "true", allowedHeaders = "*")
public class FunctionController {

    @Autowired
    FunctionService functionService;

    @Autowired
    RedisTemplate redisTemplate;

    @Autowired
    CacheService cacheService;


    @RequestMapping("/getuserfunction")
    @ResponseBody
    public CommonResult getUserFunction(@RequestParam(name = "id") Integer user_id) throws BusinessException, UnsupportedEncodingException, NoSuchAlgorithmException {
        List<String> list=functionService.getUserFunctionInfo(user_id);
        return CommonResult.create(list);
    }

    @RequestMapping("/getfunctionGraphInfo")
    @ResponseBody
    public CommonResult getFunctionGraphInfo(@RequestParam(name = "id") Integer user_id,@RequestParam(name = "function") String function) throws BusinessException, UnsupportedEncodingException, NoSuchAlgorithmException {
        return CommonResult.create(functionService.queryFunctionGraphInfo(function,user_id));
    }

    @RequestMapping("/getfunctionListInfo")
    @ResponseBody
    public CommonResult getFunctionInfo(@RequestParam(name = "id") Integer user_id,@RequestParam(name = "function") String function) throws BusinessException, UnsupportedEncodingException, NoSuchAlgorithmException {
        List<ProductInfoDO> productInfoDOList=functionService.queryFunctionListInfo(function,user_id);
        return CommonResult.create(productInfoDOList);
    }



}
